//
//  InformationCell.m
//  WeiYiMei
//
//  Created by iMac on 2019/4/24.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "InformationCell.h"

@interface InformationCell ()

@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *summaryLab;
@property (nonatomic, strong) UILabel *authorLab;
@property (nonatomic, strong) UILabel *timeLab;

@end

@implementation InformationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setEntity:(InformationEntity *)entity
{
    _entity = entity;
    NSString *imgUrl = [NSString stringWithFormat:@"%@%@",SERVERADDRS,entity.imgPath];
    [self.icon sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"pic_moren"]];
    self.titleLab.text = String(entity.title);
    self.summaryLab.text = String(entity.summary);
    self.authorLab.text = String(entity.author);
    self.timeLab.text = String(entity.dt);
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupSubViews];
    }
    return self;
}

- (void)setupSubViews
{
    self.icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic_moren"]];
    self.icon.layer.cornerRadius = 4;
    self.icon.layer.masksToBounds = YES;
    [self addSubview:self.icon];
    
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.font = [UIFont boldSystemFontOfSize:14];
    self.titleLab.textColor = kColor333333;
    [self addSubview:self.titleLab];
    
    self.summaryLab = [[UILabel alloc] init];
    self.summaryLab.font = [UIFont systemFontOfSize:12];
    self.summaryLab.textColor = kColor666666;
    self.summaryLab.numberOfLines = 2;
    [self addSubview:self.summaryLab];
    
    self.authorLab = [[UILabel alloc] init];
    self.authorLab.font = [UIFont systemFontOfSize:12];
    self.authorLab.textColor = kColor666666;
    [self addSubview:self.authorLab];
    
    self.timeLab = [[UILabel alloc] init];
    self.timeLab.font = [UIFont systemFontOfSize:12];
    self.timeLab.textColor = kColor666666;
    [self addSubview:self.timeLab];
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(kWidth(15));
        make.left.equalTo(self).offset(kWidth(15));
        make.width.equalTo(@(kWidth(115)));
        make.height.equalTo(@(75/115.0*kWidth(115)));
    }];
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.icon.mas_right).offset(kWidth(9));
        make.top.equalTo(self.icon);
        make.right.lessThanOrEqualTo(self).offset(-kWidth(15));
    }];
    
    [self.summaryLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.top.equalTo(self.titleLab.mas_bottom).offset(kWidth(10));
        make.right.lessThanOrEqualTo(self).offset(-kWidth(15));
    }];
    
    [self.authorLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.top.equalTo(self.summaryLab.mas_bottom).offset(kWidth(13));
    }];
    
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.authorLab);
        make.right.equalTo(self).offset(-kWidth(15));
    }];
}

@end
